﻿<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8" />
    <title>电器 - 冰箱</title>
    <link rel="stylesheet" href="css/animate.css"/>
    <link rel="stylesheet" href="css/font-awesome.min.css"/>
    <link rel="stylesheet" href="css/flexslider.css"/>
    <link rel="stylesheet" href="css/base.css?20150803"/>
    <style type="text/css">
        .ms-controller, [ms-controller] {
            display: none;
        }
    </style>
</head>
<body ms-controller="category">

<!-- header 顶部 -->
<header>
     <a href="index.html" style="padding-left:10px;"><img src="images/e-jialogo.png" alt="" style="width:500px;height:70px;" /></a>
    <span class="right">
        <input type="text" class="headInput" id="keyinput" placeholder="输入商品名称"/><input type="button" class="headBtn" id="btnsearch" value="搜索"/>
    </span>
</header>


<div class="road">
    <a href="javascript:history.back(-1)"><i class="fa fa-angle-left"></i></a>
    <span id="r_cat1"></span> > <span id="r_cat2"></span>
    <hr/>
</div>

<div class="fliterWrap">
    <div class="panel">
        <div class="panel-heading">
            共显示<b id="proqty">0</b>款相关产品
        </div>
        <div class="panel-body">
            <ul class="fliterUl" id="ulcat">
                <li ms-repeat-el="ctgData"><label><span>{{el.SXName}}</span>：</label>
                    <p>
                        <a class="active" ms-click="sel(el)" href="javascript:void(0);">所有</a>
                        <a ms-repeat-im="$.parseJSON(el.SXValue)" href="javascript:void(0);" ms-click="sel(el)" >{{im.SXValue}}</a>
                    </p>
                </li>
            </ul>

        </div>
    </div>

    <div class="sort">
        <a href="javascript:;" class="active">价格从低到高</a>
        <a href="javascript:;">价格从高到低</a>
    </div>

</div>


<!-- 商品列表 -->
<div class="goodList">
    <ul>
         <li ms-repeat-el="ctData" class="goodItem"><a ms-href="shopDetail.html?id={{el.ID}}"><img ms-src="{{el.ImgUrl1}}" /><p><span>{{el.Title}}</span><b>￥{{el.Price2}}</b><del>原价：￥{{el.Price1}}</del></p></a></li>
    </ul>
</div>


<script src="js/jquery.min.js"></script>
<script src="js/avalon.mobile.min.js"></script>
<script src="js/MobileCom.js"></script>
<script>

    var loc = window.localStorage.getItem("loc");
    var cat1 = MobileCom.getQueryString("cat1");
    var cat2 = MobileCom.getQueryString("cat2");

    var catn1 = MobileCom.getQueryString("catn1");
    var catn2 = MobileCom.getQueryString("catn2");

    var model = avalon.define({
        $id: "category",
        ctData: [],
        ctgData: [],
        catn1: ""
    });

    
    $(function () {
        if (window.localStorage.getItem("EUser") == null) {
            window.location = "login.html";
        }

        window.localStorage.removeItem("page");
        window.localStorage.setItem("page", 1);
        $("#r_cat1").text(catn1);
        $("#r_cat2").text(catn2);

        $.getJSON("/View/SpeList/DLLAjaxHandler.ashx?action=GetLBSX", { "LB1": catn1, "LB2": catn2 }, function (r) {

            if (r.length > 0) {
                model.ctgData = r;
                loadMore();
                
            }

        })

        $(".fliterUl li p a").click(function () {
            if ($(this).hasClass("active")) {
                $(this).removeClass("active");
            } else {
                $(this).siblings("a").removeClass("active").end().addClass("active");
            }
        });


        $(".sort a").click(function(){
            $(this).siblings("a").removeClass("active").end().addClass("active");
            window.localStorage.removeItem("page");
            window.localStorage.setItem("page", 1);

            loadMore("1");

        });

        $("#btnsearch").click(function () {
            window.location = "search.html?key=" + $("#keyinput").val();
        })
        $("#keyinput").keydown(function (e) {

            if (e.keyCode == 13) {
                window.location = "search.html?key=" + $("#keyinput").val();
            }
        })

        $(window).scroll(function () {

            if ($(document).height() - $(this).scrollTop() - $(this).height() < 5) {
                loadMore();
            }

        })
       
    });

    function sel(el) {
        if ($(this).hasClass("active")) {
            $(this).removeClass("active");
        } else {
            $(this).siblings("a").removeClass("active").end().addClass("active");
        }

        window.localStorage.removeItem("page");
        window.localStorage.setItem("page", 1);
        
        loadMore("1");
    }

    var isjz = 0;

    function loadMore(flag) {
        if (isjz == 0) {
            isjz = 1;
            var page = parseInt(window.localStorage.getItem("page"));
            if (page > 0) {

                var clist = "";
                $("#ulcat li").each(function (index, item) {

                    var txt = $(item).find("label span").text();
                    var desp = $(item).find("a.active").text();
                    if (desp != "所有") {
                        if (clist != "") {
                            clist += ",";
                        }
                        clist = '{"stext":"' + txt + '","svalue":"' + desp + '"}';
                    }

                })

                var st = $(".sort a").index($(".sort a.active"));
                if (st == "0") {
                    st = "1";
                } else if (st == "1") {
                    st = "2";
                } else {
                    st = "1";
                }


                var vcat = {
                    "cat1": cat1,
                    "cat2": cat2,
                    "Page": page,
                    "Sort": st,
                    "catlist": eval("[" + clist + "]")
                };

                var url = "/View/SpeList/DLLAjaxHandler.ashx?action=GetSPListBySX";
                if (loc != null && loc == 2) {
                    url += "&euser=" + window.localStorage.getItem("EUser");
                }

                $.getJSON(url, { "Data": JSON.stringify(vcat) }, function (r) {

                    if (r.COUNT > 0) {
                        $("#proqty").text(r.COUNT);

                        if (flag) {
                            model.ctData = $.parseJSON(r.Data);
                        } else {
                            model.ctData.pushArray($.parseJSON(r.Data));
                        }

                        var nxt = page + 1;
                        window.localStorage.setItem("page", nxt);

                    } else {
                        if (flag) {
                            model.ctData = [];
                        }
                        window.localStorage.setItem("page", 0);
                    }
                    isjz = 0;
                })

            }
        }
    }
</script>
</body>
</html>